﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using weiqijiance.model.安检联网;
using System.Xml;

namespace weiqijiance.安检联网
{
    public class angteclass:ajlwbass
    {
        public override string writeObjectOut(string jkid,string WriteXmlDoc)
        {
            if (!ssfAJLW.Contains("是"))
            {
                return "1";
            }
            m_mainform.baocunriji(jkid, WriteXmlDoc);
            return "";
        }

        public string writeObjectOut2(string jkid, string jylsh, string WriteXmlDoc)
        {

            if (!ssfAJLW.Contains("是"))
            {
                return "1";
            }
            m_mainform.baocunriji(jkid, WriteXmlDoc);
            
            WebReferenceAJ.Service objweb = new WebReferenceAJ.Service();
            objweb.Url = sweb;
            string str = objweb.writeObjectOut("18", jylsh, jkid, WriteXmlDoc);
            return AnalysisCode(str);
        
        }

        public override string SendJYXMKSSJ( string jyxm, string sbz, string gwjysbbh, string tongdao, model.安检联网.carclass objmodel)//检测项目开始和结束
        {
            string jcd = "00";
            jcd = gwjysbbh;

            if (!ssfAJLW.Contains("是"))
            {
                return "1";
            }
            string kzxh = "0";
            string sjyxx18c55 = "18C55";
            if (sbz==("开始") && !jyxm.Contains("STB2"))//处理四轮同检只抓拍一个视频
            {
                kzxh = "0";
                luxiangkais(objmodel.jylsh, tongdao, jyxm.Contains("STB1") ? "B" : jyxm, objmodel);//18C55录像开始
            }
            else if (sbz == ("结束") && !jyxm.Contains("STB2"))
            {
                kzxh = "1";
                sjyxx18c55 = "18C58";
                luxiangjieshu(objmodel.jylsh, tongdao, jyxm.Contains("STB1") ? "B" : jyxm, objmodel);//18C58录像结束
            }
            if (jyxm.Contains("STB1"))
            {
                jyxm = "B1";
            }
            if (jyxm.Contains("STB2") && sbz == ("结束"))
            {
                kzxh = "1";
            }
            if (jyxm.Contains("STB2"))
            {
                jyxm = "B2";
            }
            string vehisparaks = "";
            string stoubaowgks = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            vehisparaks = stoubaowgks + string.Format(@"<Request>
                                                            <jylsh>{0}</jylsh>
			                                                <jcd>{3}</jcd>
                                                            <jyxm>{1}</jyxm>
                                                            <kzxh>{2}</kzxh>
                                                            </Request>", objmodel.jylsh, jyxm, kzxh,jcd);

            WebReferenceAJ.Service objweb = new WebReferenceAJ.Service();
            objweb.Url = sweb;
            m_mainform.baocunriji("T04", vehisparaks);
            string str = objweb.writeObjectOut("18", objmodel.jylsh, "T04", vehisparaks);
            return AnalysisCode(str);

        }
       

        public override string write(carclass objmodel, modelA1 objbass)
        {
            string C13model = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jcxdh>{1}</jcxdh>
						<jyxm>{2}</jyxm>
                        <jycs>{3}</jycs>
						<chz>{4}</chz>
						<chpd>{5}</chpd>
						</Request>",
                          objmodel.jylsh,
                          objmodel.jcxdh,
                          "A1",
                          objmodel.jycs,
                          objbass.chz,
                          objbass.chpd);
            //数据上传
            return writeObjectOut2("C13", objmodel.jylsh, C13model);
        }

        public override string write(carclass objmodel, modelC1 objbass)
        {
            string A03model = string.Format("<item zd=\"rzxxbj\">{0}</item>", objbass.rzxxbj) +
                string.Format("<item zd=\"rcdxbj\">{0}</item>", objbass.rcdxbj)+
                string.Format("<item zd=\"rxsxbj\">{0}</item>", objbass.rxsxbj)+
                string.Format("<item zd=\"rzdxbj\">{0}</item>", objbass.rzdxbj)+
                string.Format("<item zd=\"rqtbj\">{0}</item>", objbass.rqtbj);
            string A03 = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jyxm>{1}</jyxm>
						<jyy>{2}</jyy>
                        <jyysfzh>{3}</jyysfzh>
                        <jysj>{4}</jysj>
						</Request>",
                          objmodel.jylsh,
                          "C1",
                          "test",
                          "445281199501013034", A03model);//problem,身份证和检验员
            //数据上传
            return writeObjectOut2("A03", objmodel.jylsh, A03);
        }

        public override string write(carclass objmodel, modelB objbass, int ivax)
        {
            //安检数据检测数据上传
            string[] zlz = { "yzzlz", "ezzlz", "sanzzlz", "sizzlz", "wzzlz" };//一轴左静态轮荷
            string[] ylz = { "yzylz", "ezylz", "sanzylz", "sizylz", "wzylz" };//一轴右静态轮荷
            string[] kzzh = { "yzkzzh", "ezkzzh", "sanzkzzh", "sizkzzh", "wzkzzh" };//一轴空载轴荷
            string[] qhzzdl = { "yzqhzzdl", "ezqhzzdl", "sanzqhzzdl", "sizqhzzdl", "wzqhzzdl" };//一轴最大左行车制动力值
            string[] qhyzdl = { "yzqhyzdl", "ezqhyzdl", "sanzqhyzdl", "sizqhyzdl", "wzqhyzdl" };//一轴最大右行车制动力值
            string[] qczzdl = { "yzqczzdl", "ezqczzdl", "sanzqczzdl", "sizqczzdl", "wzqczzdl" };//一轴最大左制动力差值

            string[] qcyzdl = { "yqqcyzdl", "ezqcyzdl", "sanzqcyzdl", "sizqcyzdl", "wzqcyzdl" };//最大右制动力差值
            string[] dll = { "yzdll", "ezdll", "sanzdll", "sizdll", "wzdll" };//行车制动率
            string[] zdlpd = { "yzzdlpd", "ezzdlpd", "sanzzdlpd", "sizzdlpd", "wzzdlpd" };//行车制动率判定
            string[] bphl = { "yzbphl", "ezbphl", "sanzbphl", "sizbphl", "wzbphl" };//不平衡率
            string[] bphlpd = { "yzbphlpd", "ezbphlpd", "sanzbphlpd", "sizbphlpd", "wzbphlpd" };//不平衡率判定
            string[] zdpd = { "yzzdpd", "ezzdpd", "sanzzdpd", "sizzdpd", "wzzdpd" };//制动判定
            string[] zldtlh = { "yzzldtlh", "ezzldtlh", "sanzzldtlh", "sizzldtlh", "wzzldtlh" };//左轮动态轮荷
            string[] yldtlh = { "yzyldtlh", "ezyldtlh", "sanzyldtlh", "sizyldtlh", "wzyldtlh" };//右轮动态轮荷
            string[] zdlqx = { "yzzdlqx", "ezzdlqx", "sanzzdlqx", "sizzdlqx", "wzzdlqx" };//制动力曲线
            string jyxm = "";
            if (ivax == 0) jyxm = "B1";
            if (ivax == 1) jyxm = "B2";
            if (ivax == 2) jyxm = "B3";
            if (ivax == 3) jyxm = "B4";
            if (ivax == 4) jyxm = "B5";
            string daihao = "";
            if (ivax == 0) daihao = "C01";
            if (ivax == 1) daihao = "C02";
            if (ivax == 2) daihao = "C03";
            if (ivax == 3) daihao = "C04";
            if (ivax == 4) daihao = "C05";
            //if (ivax == 5) jyxm = "B6";
            string s18C81 = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jcxdh>{1}</jcxdh>
                        <jyxm>{2}</jyxm>
						<jycs>{3}</jycs>
						<{19}>{4}</{19}>
						<{20}>{5}</{20}>
                        <{21}>{6}</{21}>
                        <{22}>{7}</{22}>
                        <{23}>{8}</{23}>
                        <{24}>{9}</{24}>
                        <{25}>{10}</{25}>
                        <{26}>{11}</{26}>
                        <{27}>{12}</{27}>
                        <{28}>{13}</{28}>
                        <{29}>{14}</{29}>
                        <{30}>{15}</{30}>
                        <{31}>{16}</{31}>
                        <{32}>{17}</{32}>
                        <{33}>{18}</{33}>
						</Request>",
                          objmodel.jylsh,
                          objmodel.jcxdh,
                          jyxm,
                          objmodel.jycs,
                          objbass.zlz,
         objbass.ylz,
         objbass.kzzh,
         objbass.qhzzdl,
         objbass.qhyzdl,
         objbass.qczzdl,
         objbass.qcyzdl,
         objbass.dll,
         objbass.zdlpd,
         objbass.bphl,
         objbass.bphlpd,
         objbass.zdpd,
         objbass.zldtlh,
         objbass.yldtlh,
         objbass.zdlqx,
                          zlz[ivax],
                          ylz[ivax],
                          kzzh[ivax],
                          qhzzdl[ivax],
                          qhyzdl[ivax],
                          qczzdl[ivax],
                          qcyzdl[ivax],
                          dll[ivax],
                          zdlpd[ivax],
                          bphl[ivax],
                          bphlpd[ivax],
                          zdpd[ivax],
                          zldtlh[ivax],
                          yldtlh[ivax],
                          zdlqx[ivax]);
            //数据上传
            return writeObjectOut2(daihao, objmodel.jylsh, s18C81);
        }

        public override string write(carclass objmodel, modelB0 objbass)
        {
            string C07model = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jcxdh>{1}</jcxdh>
                        <jyxm>{2}</jyxm>
						<jycs>{3}</jycs>
						<yzzczdl>{4}</yzzczdl>
						<ezzczdl>{5}</ezzczdl>
                        <sanzzczdl>{6}</sanzzczdl>
                        <sizzczdl>{7}</sizzczdl>
                        <wzzczdl>{8}</wzzczdl>
                        <zczczdl>{9}</zczczdl>
                        <tczzdl>{10}</tczzdl>
                        <tcyzdl>{11}</tcyzdl>
                        <tczdl>{12}</tczdl>
                        <tczdpd>{13}</tczdpd>
						</Request>",
                    objmodel.jylsh,
                    objmodel.jcxdh,
                    "B0",
                    objmodel.jycs,
                    objbass.yzzczdl,
                    objbass.ezzczdl,
                    objbass.sanzzczdl,
                    objbass.sizzczdl,
                    objbass.wzzczdl,
                    objbass.zczczdl,
                    objbass.tczzdl,
                    objbass.tcyzdl,
                    objbass.tczdl,
                    objbass.tczdpd);
            //数据上传
            return writeObjectOut2("C07", objmodel.jylsh, C07model);

        }

        public override string write(carclass objmodel, modelL objbass, int ivax)
        {
            string jyxm = "";
            if (ivax == 0) jyxm = "L1";
            if (ivax == 1) jyxm = "L2";
            if (ivax == 2) jyxm = "L3";
            if (ivax == 3) jyxm = "L4";
            if (ivax == 4) jyxm = "L5";
            string C16model = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jcxdh>{1}</jcxdh>
                        <jyxm>{2}</jyxm>
						<jycs>{3}</jycs>
						<qhzzdl>{4}</qhzzdl>
						<qhyzdl>{5}</qhyzdl>
                        <qczzdl>{6}</qczzdl>
                        <qcyzdl>{7}</qcyzdl>
                        <dll>{8}</dll>
                        <zdlpd>{9}</zdlpd>
                        <bphl>{10}</bphl>
                        <bphlpd>{11}</bphlpd>
                        <zdpd>{12}</zdpd>
                        <zljzlh>{13}</zljzlh>
                        <yljzlh>{14}</yljzlh>
                        <zdlqx>{15}</zdlqx>
						</Request>",
                          objmodel.jylsh,
                          objmodel.jcxdh,
                          jyxm,
                          objmodel.jycs,
                        objbass.qhzzdl,
                        objbass.qhyzdl,
                        objbass.qczzdl,
                        objbass.qcyzdl,
                        objbass.dll,
                        objbass.zdlpd,
                        objbass.bphl,
                        objbass.bphlpd,
                        objbass.zdpd,
                        objbass.zljzlh,
                        objbass.yljzlh,
                        objbass.zdlqx);
            return writeObjectOut2("C16", objmodel.jylsh, C16model);
        }

        public override string write(carclass objmodel, modelH1 objbass)
        {
            //左主灯
            string C08model = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jcxdh>{1}</jcxdh>
                        <jyxm>{2}</jyxm>
						<jycs>{3}</jycs>
						<zdg>{4}</zdg>
						<zwjgdg>{5}</zwjgdg>
                        <zwygqd>{6}</zwygqd>
                        <zwygqdpd>{7}</zwygqdpd>
                        <zwygszpz>{8}</zwygszpz>
                        <zjgszcz>{9}</zjgszcz>
                        <zwygczpy>{10}</zwygczpy>
                        <zwjgczpy>{11}</zwjgczpy>
                        <zwygczpypd>{12}</zwygczpypd>
                        <zwjgczpypd>{13}</zwjgczpypd>
                        <zwdpd>{14}</zwdpd>
						</Request>",
                        objmodel.jylsh,
                        objmodel.jcxdh,
                        "H1",
                        objmodel.jycs,
                        objbass.zdg,
                        objbass.zwjgdg,
                        objbass.zwygqd,
                        objbass.zwygqdpd,
                        objbass.zwygszpz,
                        objbass.zjgszcz,
                        objbass.zwygczpy,
                        objbass.zwjgczpy,
                        objbass.zwygczpypd,
                        objbass.zwjgczpypd,
                        objbass.zwdpd);
            return writeObjectOut2("C08", objmodel.jylsh, C08model);
        }

        public override string write(carclass objmodel, modelH4 objbass)
        {
            //右主灯
            string C11model = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jcxdh>{1}</jcxdh>
                        <jyxm>{2}</jyxm>
						<jycs>{3}</jycs>
						<ydg>{4}</ydg>
						<ywjgdg>{5}</ywjgdg>
                        <ywygqd>{6}</ywygqd>
                        <ywygqdpd>{7}</ywygqdpd>
                        <ywygszpz>{8}</ywygszpz>
                        <yjgszcz>{9}</yjgszcz>
                        <ywygczpy>{10}</ywygczpy>
                        <ywjgczpy>{11}</ywjgczpy>
                        <ywygczpypd>{12}</ywygczpypd>
                        <ywjgczpypd>{13}</ywjgczpypd>
                        <ywdpd>{14}</ywdpd>
						</Request>",
                        objmodel.jylsh,
                        objmodel.jcxdh,
                        "H4",
                        objmodel.jycs,
                        objbass.ydg,
                                      objbass.ywjgdg,
                                      objbass.ywygqd,
                                      objbass.ywygqdpd,
                                      objbass.ywygszpz,
                                      objbass.yjgszcz,
                                      objbass.ywygczpy,
                                      objbass.ywjgczpy,
                                      objbass.ywygczpypd,
                                      objbass.ywjgczpypd,
                                      objbass.ywdpd);
            return writeObjectOut2("C11", objmodel.jylsh, C11model);
        }

        public override string write(carclass objmodel, modelS1 objbass)
        {
            string C12model = string.Format("<?xml version=\"1.0\" encoding=\"GBK\"?>" + @"<Request>
						<jylsh>{0}</jylsh>
						<jcxdh>{1}</jcxdh>
						<jyxm>{2}</jyxm>
                        <jycs>{3}</jycs>
                        <csdscz>{4}</csdscz>
                        <csbpd>{5}</csbpd>
						</Request>",
                          objmodel.jylsh,
                          "1",
                          "S1",
                          objmodel.jycs,
                          objbass.csdscz,
                          objbass.csbpd);
            //数据上传
            return writeObjectOut2("C12", objmodel.jylsh, C12model);

        }

        public override string write(carclass objmodel, model18C82 model18C82)
        {
            //总结束全国：18C82/18C59/18C61   
            string S02model = "";
            string stoubao18C82 = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            S02model = stoubao18C82 + string.Format(@"<Request>
                            <jylsh>{0}</jylsh>
                            <ycyxm>{1}</ycyxm>
                            <ycysfzh>{2}</ycysfzh>
                             <zczdl>{3}</zczdl>
                             <zczdpd>{4}</zczdpd>
                             <zczdjyjg>{5}</zczdjyjg>
                             <zdjccs>{6}</zdjccs>
                            <zcpd>{7}</zcpd>
                            <zjccs>{8}</zjccs>
                            <jczczbzl>{9}</jczczbzl>
                            <bzzczbzl>{10}</bzzczbzl>
                            <zczbzlbfb>{11}</zczbzlbfb>
                            <zbzlpd>{12}</zbzlpd>
                            </Request>",
                       objmodel.jylsh,
                       model18C82.ycyxm,
                       "445281199501013034",//身份证problem
                       model18C82.zczdl,//整车制动率
                       model18C82.zczdpd,//整车制动判定
                        "0",//主车制动检验结果
                       model18C82.zdjccs,//整车制动次数
                       model18C82.zcpd,//整车判定
                       model18C82.zjccs,//总检验次数
                       model18C82.jczczbzl,//检验的整车整备质量
                       model18C82.bzzczbzl,//标准的整车整备质量
                       model18C82.zczbzlbfb,//整车整备质量百分比
                       model18C82.zbzlpd);//整备质量判定
            return writeObjectOut2("S02", objmodel.jylsh, S02model);

        }

        public override string write(carclass objmodel, model18C62 model18C62)
        {
            string vehispara18C62 = "";
            string stoubao18C62 = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            vehispara18C62 = stoubao18C62 + string.Format(@"<Request>
                            <jylsh>{0}</jylsh>
                            <jyjl>{1}</jyjl>
                            <pzrxm>{2}</pzrxm>
                            <rgjyjgs>{3}</rgjyjgs>
                            <yqsbjyjgs>{4}</yqsbjyjgs>
                            <jybgjy>{5}</jybgjy>
                            <jybgbz>{6}</jybgbz>
                            </Request>",
                   objmodel.jylsh,
                   model18C62.jyjl,
                   model18C62.pzrxm,//问题
                   model18C62.rgjyjgs,
                   model18C62.yqsbjyjgs,
                   model18C62.jybgjy,
                   model18C62.jybgbz);
            return writeObjectOut2("S03", objmodel.jylsh, vehispara18C62);

        }

        public override string write(carclass objmodel, modelZ1 objbass)
        {
            string QueryXmlDoc = "";
            string stou = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            QueryXmlDoc = stou + string.Format(@"<Request>
                                                <jylsh>{0}</jylsh>
                                                <jcxdh>{1}</jcxdh>
                                                <jyxm>{2}</jyxm>
                                                <jycs>{3}</jycs>
                                                <zbzl>{4}</zbzl>
                                                <zbzlpd>{5}</zbzlpd>
                                                </Request>",
                                                objmodel.jylsh,
                                                objmodel.jcxdh,
                                                "Z1",
                                                objmodel.jycs,
                                                objbass.zbzl,
                                                objbass.zbzlpd);

            return writeObjectOut2("C15", objmodel.jylsh, QueryXmlDoc);
        }

        public override string write(carclass objmodel, modelM1 objbass)
        {
            string stoubaosj = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            string WriteXmlDoc = stoubaosj + string.Format(@"
			<Request>
			<jylsh>{0}</jylsh>
			<jcxdh>{1}</jcxdh>
			<jyxm>{2}</jyxm>
			<jycs>{3}</jycs>
            <cwkc>{4}</cwkc>
            <cwkk>{5}</cwkk>
            <cwkg>{6}</cwkg>
            <clwkccpd>{7}</clwkccpd>
			</Request>", objmodel.jylsh, objmodel.jcxdh, "M1", objmodel.jycs,
            objbass.cwkc, objbass.cwkk, objbass.cwkg, objbass.clwkccpd);

            return writeObjectOut2("C14", objmodel.jylsh, WriteXmlDoc);

        }

        public string AnalysisCode(string code)
        {
            string revert = "1";
            try
            {
                XmlDocument xmlstrks = new XmlDocument();
                xmlstrks.LoadXml(code);
                if (!(xmlstrks.SelectSingleNode("/Response/code").InnerText == "000"))
                {
                    string jieguo = xmlstrks.SelectSingleNode("/Response/message").InnerText;
                    string str = xmlstrks.SelectSingleNode("/Response/code").InnerText;
                    revert = "0:" + ":" + jieguo;
                }
            }
            catch { revert = "0:" + ":" + code; }
            return revert;
        }

        public override string sendAJend(string jylsh, bool bbz,bool bzt)//发送检测结束
        {
            if (!ssfAJLW.Contains("是")||bzt)
            {
                return "1";
            }
            WebReferenceAJ.Service objweb = new WebReferenceAJ.Service();
            objweb.Url = sweb;

            string str = objweb.sendAJend(jylsh, bbz);
            return AnalysisCode(str);
        }
       

    }
}
